home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / risc_src.lha / risc_sources / sparc / sparcassist.c < prev   
C/C++ Source or Header  |  1989-09-25  |  3KB  |  136 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <nlist.h>
  4.  
  5. #define IF ((
  6. #define THEN )?(
  7. #define ELSE ):(
  8. #define FI ))
  9.  
  10. #define MIN_HEAP_SIZE 524288  /* .5 Mb */
  11. #define DEFAULT_HEAP_SIZE 4096000 /* 4 Mb  */
  12. #define STDIO_SPACE   49152   /* be sure to save 48k of data space for stdio */
  13. #define STATIC_SPACE  131072  /* .125Mb for fun, usr "-l" to add to this */
  14. #define SAVED_SPACE   (STDIO_SPACE+STATIC_SPACE)
  15.  
  16.  
  17. main( argc, argv )
  18. char **argv;
  19. int argc;
  20. {
  21.     long heap_wanted = -1;
  22.     long leave_wanted = -1;
  23.     long debug = 0;
  24.  
  25.     long
  26.     heap_size;
  27.               
  28.     long
  29.     total,
  30.     aligned_total,
  31.     aligned_heap_size;
  32.  
  33.     char **av;
  34.  
  35.     av = argv;
  36.     av[argc] = 0; /* easy end test */
  37.  
  38.     while (*av)  {
  39.     if ( ( !strcmp( *av, "-h" ) ) || ( !strcmp( *av, "-heap" ) ) )
  40.         heap_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  41.     else if ( ( !strcmp( *av, "-l" ) ) || ( !strcmp( *av, "-leave" ) ) )
  42.         leave_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  43.     else if (!strcmp( *av, "-d" ) )
  44.         debug = -1;
  45.     av++;
  46.     }
  47.  
  48.     /* Compute max allowed heap size.  MIN in case datasize is big. */
  49.     /*  Quad align. */
  50.  
  51.     /* decide what to allocate - give user his request if it's within reason */
  52.  
  53.     if ((heap_wanted == -2))
  54.     heap_size = DEFAULT_HEAP_SIZE;
  55.     else                      
  56.     if (heap_wanted == -1)
  57.     heap_size = DEFAULT_HEAP_SIZE;
  58.     else
  59.     if (heap_wanted > MIN_HEAP_SIZE)
  60.     heap_size = heap_wanted;
  61.     else
  62.     heap_size = MIN_HEAP_SIZE;
  63.  
  64.     total = sbrk( heap_size * 2 );
  65.     if (total == -1)  {
  66.     printf( "T could not allocate two heaps of %d bytes.\n", heap_size);
  67.     printf( "Please retry with smaller heaps by using the -h switch.\n");
  68.     exit(1);
  69.     }
  70.         
  71.     /* make heaps smaller (if necessary) for quadword alignment */
  72.  
  73.     aligned_total = (total + 15) & 0xFFFFFFF0;
  74.     aligned_heap_size = ( ((heap_size * 2) - (aligned_total - total))
  75.               & 0xFFFFFFC0 );
  76.  
  77.     heap_size = aligned_heap_size / 2;
  78.  
  79.     /* print message if any command line flag is given */
  80.  
  81.     if ( (heap_wanted != -1) || (leave_wanted != -1) )
  82.     printf( "%d bytes per heap, %d bytes reserved\n",
  83.         heap_size, leave_wanted + STATIC_SPACE );
  84.  
  85.     start_t( aligned_total, (aligned_total + heap_size), heap_size, 
  86.              argc, argv, debug);
  87.  
  88. }
  89.  
  90. gc_interrupt()
  91. {
  92.   printf("Interrupted during GC; 'q' to exit, anything else to continue GC.\n");
  93.   if (getchar() == 'q')
  94.      exit(0);
  95. }
  96.  
  97. extern int errno;
  98. extern char *sys_errlist[];
  99. extern int sys_nerr;
  100.  
  101. get_unix_error_msg(t, size) 
  102. char *t;
  103. int size; 
  104. {
  105.   char *s;    
  106.   int i;
  107.  
  108.   i = 0;
  109.   s = (char *) sys_errlist[ errno ];
  110.   while (i<size && ((*t++ = *s++) != '\0')) i++; 
  111. }
  112.  
  113. /*
  114.  * return the address of the function functionName in the namelist 
  115.  * of the file fileName.
  116.  * the calling procedure had better make sure that fileName exists.
  117.  */
  118. unsigned long
  119. nlistone(fileName,functionName)
  120. char *fileName, *functionName;
  121. {
  122. struct nlist nl[2];
  123. int rc;
  124.  
  125. nl[1].n_name = '\0'; /* terminate the name list */
  126. nl[0].n_name = functionName; /* put the function name in */
  127. rc = nlist(fileName,nl); /* call nlist */
  128. if (rc < 0 || (nl[0].n_type == (unsigned char) 0 /* check for errors */
  129.        && nl[0].n_value == (unsigned long) 0))
  130.     return ((unsigned long) 0);
  131. if (nl[0].n_type & N_TEXT) /* if it is in the text segment i.e. is a function */
  132.     return(nl[0].n_value); /* return the address */
  133. else
  134.     return ((unsigned long) 0); /* not a function */
  135. }
  136.